import { reqGoodsInfo,reqAddOrUpdateShopCart } from "@/api"
//封装游客身份模块uuid
import{getUUID} from '@/utils/uuid_token'
const actions={
    async getGoodInfo(context,skuId){
    let result = await reqGoodsInfo(skuId)
    if(result.code==200){
        context.commit('GETGOODINFO',result.data)
    }

    },
    async addOrUpdateShopCart(context,{skuId,skuNum}){
        let result= await reqAddOrUpdateShopCart(skuId,skuNum)
         if(result.code==200){
            return 'ok'
         }else{
            return Promise.reject(new Error('faile'))
         }
        
    }
}
const mutations={
    GETGOODINFO(state,goodInfo){
       state.goodInfo=goodInfo
    },
    ADDORUPDATESHOPCART(state,){

    }
}
const state={
    goodInfo:{},
    uuid_token:getUUID()
}
//为简化数据而生
const getters={
    categoryView(state){
      return state.goodInfo.categoryView || {}
    },
    skuInfo(state){
        return state.goodInfo.skuInfo || {}
    },
    spuSaleAttrList(state){
        return state.goodInfo.spuSaleAttrList || []
    }
}

export default{
    actions,mutations,state,getters
}